import 'package:flutter/material.dart';
import 'package:flutter_demo/chapter4-LayoutWidget/layout/LayoutBuilderWidget.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Transform Widget Demo"),
      ),
      body: wRowWidget(),
    ),
  ));
}

class wRowWidget extends StatelessWidget {
  const wRowWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    LayoutLogPrint(tag: 1, child: wRow(" 800 "),);
    FittedBox(child: LayoutLogPrint(tag:2, child: wRow(" 800 "),),);
    return Center(
      child: Column(
        children: [
          wRow(" 90000000000000000000000 "),
          SingleLineFittedBox(child: wRow(" 90000000000000000000000 "),),
          wRow(" 800 "),
          SingleLineFittedBox(child: wRow( " 800 "),)
        ],
      ),

    );
  }

  Widget wRow(String text) {
    Widget child = Text(text);
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        child, child, child
      ],
    );
  }

}

class SingleLineFittedBox extends StatelessWidget {
  const SingleLineFittedBox({Key? key, required this.child}) : super(key:key);

  final Widget child;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (_, constraints) {
      return FittedBox(
        child: ConstrainedBox(
          constraints: constraints.copyWith(
            minWidth: constraints.maxWidth,
            maxWidth: double.infinity,
          ),
          child: child,
        ),
      );
    });
  }
}
